//
//  StatusOriginalView.swift
//  微博项目
//
//  Created by mac on 16/1/19.
//  Copyright © 2016年 mac. All rights reserved.
//

import UIKit
import SnapKit

class StatusOriginalView: UIView {

    var status: Status?{
    
        didSet{
        
            //绑定数据
            headImage.sd_setImageWithURL(status?.user?.headImageURL, placeholderImage: UIImage(named: "avatar_default_big"))
            nameLabel.text = status?.user?.name
            mbrankImage.image = status?.user?.mbrank_image
            verifiedTypeImage.image = status?.user?.verified_type_image
            timeLabel.text = status?.created_at
            sourceLabel.text = status?.source
            contentLabel.text = status?.text
            pictureView.imageURLs = status?.imageURLs
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
   private func setupUI(){
    backgroundColor=UIColor.greenColor()
    addSubview(headImage)
    addSubview(nameLabel)
    addSubview(mbrankImage)
    addSubview(timeLabel)
    addSubview(sourceLabel)
    addSubview(verifiedTypeImage)
    addSubview(contentLabel)
    addSubview(pictureView)
    
    //头像的圆角设置
    headImage.layer.cornerRadius = 17.5
    headImage.layer.masksToBounds = true
    pictureView.backgroundColor = UIColor.purpleColor()
    
   //设置约束
    headImage.snp_makeConstraints { (make) -> Void in
        make.top.equalTo(self.snp_top).offset(StatusCellMargin)
        make.left.equalTo(self.snp_left).offset(StatusCellMargin)
        make.size.equalTo(CGSize(width: StatusCellImageWidth, height: StatusCellImageWidth))
    }
    
    nameLabel.snp_makeConstraints { (make) -> Void in
        make.top.equalTo(headImage.snp_top)
        make.left.equalTo(headImage.snp_right).offset(StatusCellMargin)

   }
    //用户等级
    mbrankImage.snp_makeConstraints { (make) -> Void in
        make.top.equalTo(nameLabel.snp_top)
        make.left.equalTo(nameLabel.snp_right).offset(StatusCellMargin)
        
    }
    //微博时间
    timeLabel.snp_makeConstraints { (make) -> Void in
        make.left.equalTo(headImage.snp_right).offset(StatusCellMargin)
        make.bottom.equalTo(headImage.snp_bottom)
    }
    //微博来源
    sourceLabel.snp_makeConstraints { (make) -> Void in
        make.left.equalTo(timeLabel.snp_right).offset(StatusCellMargin)
        make.top.equalTo(timeLabel.snp_top)
    }
    //微博认证类型
    verifiedTypeImage.snp_makeConstraints { (make) -> Void in
//        make.top.equalTo(headImage.snp_bottom).offset(StatusCellMargin)
        make.right.equalTo(headImage.snp_right)
        make.bottom.equalTo(headImage.snp_bottom)
    }
    //微博正文
    contentLabel.snp_makeConstraints { (make) -> Void in
        make.top.equalTo(headImage.snp_bottom).offset(StatusCellMargin)
        make.left.equalTo(headImage.snp_left)
    }
    //配图视图
    pictureView.snp_makeConstraints { (make) -> Void in
        make.top.equalTo(contentLabel.snp_bottom).offset(StatusCellMargin)
        make.left.equalTo(contentLabel.snp_left)
        make.size.equalTo(CGSize(width: 100, height: 100))
    }
    
    
    self.snp_makeConstraints { (make) -> Void in
        make.bottom.equalTo(pictureView.snp_bottom).offset(StatusCellMargin)
    }
    
    }
    
    //懒加载所有子视图
    private lazy var headImage: UIImageView = UIImageView()
    private lazy var nameLabel:UILabel = UILabel(title: "你是不是傻", fontSize: 14, color: themeColor)
    //用户等级
    private lazy var mbrankImage:UIImageView = UIImageView(image: UIImage(named: "common_icon_membership"))
    //微博时间
    private lazy var timeLabel:UILabel = UILabel(title: "22:22", fontSize: 10, color: UIColor.lightGrayColor())
    
    //微博来源
    private lazy var sourceLabel:UILabel = UILabel(title: "22期的同学们", fontSize: 10, color: UIColor.lightGrayColor())
    //微博认证类型 verifiedTypeImage
    private lazy var verifiedTypeImage:UIImageView = UIImageView(image: UIImage(named:"avatar_vip"))
    //微博正文  contentLabel
    private lazy var contentLabel:UILabel = UILabel(title: "北京的冬天好冷啊", fontSize: 14, color: UIColor.darkGrayColor(),margin: StatusCellMargin)
    //配图视图  pictureView
    private lazy var pictureView:StatusCellPictureView = StatusCellPictureView()
    
    
    
    

}
